package com.elecbook.system.controller;

import com.elecbook.base.dto.PageDTO;
import com.elecbook.base.result.Result;
import com.elecbook.system.model.dto.PropertiesBatchDTO;
import com.elecbook.system.model.dto.PropertiesDTO;
import com.elecbook.system.model.dto.PropertiesPQuery;
import com.elecbook.system.model.po.Properties;
import com.elecbook.system.service.PropertiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Z-ken
 * @since 2024/11/11 16:54:34
 */
@RestController
@RequestMapping("/properties")
public class PropertiesController {
    @Autowired
    private PropertiesService propertiesService;

    @PostMapping("/key")
    String getPropertyValue(@RequestBody PropertiesDTO dto) {
        return propertiesService.getValue(dto);
    }

    @PostMapping("/r/key")
    String rGetPropertyValue(@RequestBody PropertiesDTO dto) {
        return propertiesService.getValue(dto);
    }

    @PostMapping("/keys")
    List<Properties> getFontEndSystemProperties(@RequestBody PropertiesBatchDTO propertiesBatchDTO) {
        return propertiesService.getProperties(propertiesBatchDTO);
    }




    /*
    管理员生成方法
    */

    @PostMapping("/op/save")
    Result<Properties> save(@RequestBody Properties properties) {
        Properties res = propertiesService.saveProperties(properties);
        return Result.success(res);
    }

    @DeleteMapping("/op/{id}")
    Result<String> delete(@PathVariable Long id) {
        propertiesService.removeById(id);
        return Result.success();
    }

    @GetMapping("/op/{id}")
    Result<Properties> get(@PathVariable Long id) {
        Properties res =  propertiesService.getById(id);
        return Result.success(res);
    }

    @PutMapping("/op/update")
    Result<Properties> update(@RequestBody Properties properties) {
        Properties res =  propertiesService.updatePropertiesById(properties);
        return Result.success(res);
    }

    @PostMapping("/op/page")
    Result<PageDTO<Properties>> page(@RequestBody PropertiesPQuery propertiesQuery) {
        PageDTO<Properties> pageResult = propertiesService.pageQuery(propertiesQuery);
        return Result.success(pageResult);
    }
}
